<style type="text/css"></style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="地址" prop="address">
            <i-input v-model="formValidate.address" placeholder="请输入岗位地址"></i-input>
        </Form-item>
        <Form-item label="电话" prop="phone">
            <i-input v-model="formValidate.phone" placeholder="请输入岗位电话"></i-input>
        </Form-item>
        <Form-item label="摄像头信息" prop="Camerainfos">
            <i-input v-model="formValidate.Camerainfos" placeholder="请输入摄像头信息"></i-input>
        </Form-item>
        <Form-item label="级别" prop="Gangweilevel">
            <i-select v-model="formValidate.Gangweilevel" placeholder="请选择级别">
                <i-option value="1">1</i-option>
                <i-option value="2">2</i-option>
                <i-option value="3">3</i-option>
                <i-option value="4">4</i-option>
                <i-option value="5">5</i-option>
                <i-option value="6">6</i-option>
            </i-select>
        </Form-item>
        <Form-item label="人员数" prop="Personcount">
            <i-input v-model="formValidate.Personcount" placeholder="请输入人员数量"></i-input>
        </Form-item>
        <Form-item label="岗位描述" prop="Description">
            <i-input v-model="formValidate.Description" placeholder="请输入岗位描述"></i-input>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    address: '',
                    phone: '',
                    Gangweilevel: '',
                    Camerainfos: '',
                    Personcount: '',
                    Description:'',
                },
                ruleValidate: {
                    address: [
                        {required: true, message: '地址不能为空', trigger: 'blur'}
                    ],
                    phone: [
                        {required: true, message: '电话不能为空', trigger: 'blur'},
                    ],
                    Gangweilevel: [
                        {required: true, message: '请选择级别', trigger: 'change'}
                    ],
                    Camerainfos: [
                        {required: true, message: '摄像机信息不能为空', trigger: 'blur'}
                    ],
                    Personcount: [
                        {required: true, message: '人员数量不能为空', trigger: 'blur'}
                    ],
                },
            }
        },
        mounted: function () {
            let id = this.$route.query.id;

            if (id && id.length > 0) {

                this.getDetail(id)
            }

        },

        methods: {
            changeOutDate: function (date) {
                console.log(date)
                this.formValidate.outdate = date;
            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.updateData(model);
                })
            },
            //详情
            getDetail: function (id) {
                let that = this;
                that.$Loading.start();

                let para = {
                    id: id,
                };

                apiUtil.get(that, apiUtil.urls.StationDetails, para, function (res) {
                    that.$Loading.finish();
                    that.formValidate.address = res.Msg.address;
                    that.formValidate.phone = res.Msg.phone;
                    that.formValidate.Camerainfos = res.Msg.camerainfos;
                    that.formValidate.Gangweilevel = res.Msg.gangweilevel.toString();
                    that.formValidate.Personcount = res.Msg.personcount;
                    that.formValidate.Description = res.Msg.description;
                    that.getPaperData();
                });
            },
            //修改
            updateData: function (model) {
                let that = this;

                model.id = this.$route.query.id;

                let params = that.$qs.stringify(model);

                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.StationEdit, params, function (res) {
                    that.$Loading.finish();
                    that.$message.success('编辑成功')
                });
            },


        }
    }
</script>
